
layui.use(['table', 'form', 'laydate', 'jquery', 'element'], function () {
    var table = layui.table;
    var element = layui.element;
    var $ = layui.$;
    var setter = layui.setter;
    var form = layui.form;
    var laydate = layui.laydate;
    var tableId = $("#tableId").val();
    // 第一个实例
    var tableIns = table.render({
        elem: '#table'
        , height: 'full-200'
        , url: '/log/findLogBy?id=' + tableId //数据接口
        , cellMinWidth: 40
        , page: true //开启分页
        /* , request: {
             pageName: 'pageNum' //页码的参数名称，默认：page
             , limitName: 'pageSize' //每页数据量的参数名，默认：limit
         }*/
        , cols: [
            [ //表头id
                {field: 'logTitle', title: '日志标题', sort: true, align: 'center'}
                , {field: 'belongProject', title: '所属项目', sort: true, align: 'center'}
                , {
                field: 'logPletionTime', title: '填写时间', sort: true, align: 'center', templet: function (d) {
                    var date = new Date(d.logPletionTime)
                    var month = parseInt(date.getMonth()) + 1
                    return date.getFullYear() + "-" + month + "-" + date.getDate()
                }
            }, {field: 'logDescription', title: '任务描述', align: 'center'}

            ]
        ]
    });
    //日期控件
    laydate.render({
        elem: '.startDate'
    });
    laydate.render({
        elem: '.endDate'
    });
    //查询提交数据并重载
    form.on('submit(formSub)', function (data) {
        var filed = data.field;
        //执行重载
        tableIns.reload({
            where: {
                logTitle: filed.logTitle
                , startDate: filed.startDate
                , endDate: filed.endDate
            }, page: {
                curr: 1
            }
        })
        return false;
    });
//头工具栏事件
    table.on('toolbar(table)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id);
        switch (obj.event) {
            case 'add':
                layer.open({
                    type: 2
                    , title: "新增"
                    , area: ['50%', '70%']
                    , content: "/view/writeLog"
                });
                break;
            case 'delete':
                var data = checkStatus.data;
                layer.msg('选中了：' + data.length + ' 个');
                break;
                /*   case 'query':
                       form.on('submit(formSub)', function (data) {
                           /!*layer.msg(JSON.stringify(data.field));*!/

                           return false;
                       });*/
                break;
        }
        ;
    });
    //监听行工具事件
    table.on('tool(table)', function (obj) {
        var data = obj.data;
        var jsonData = JSON.stringify(data)

        //获取到该行id
        var tableId = {"logId": data.logId};

        if (obj.event === 'edit') {
            layer.open({
                type: 2
                , title: "编辑"
                , area: ['50%', '70%']
                , content: "/view/updateLog?logId=" + tableId.logId
            });
        } else if (obj.event === 'workNote') {
            layer.open({
                content: '看个锤子你看。隐私你懂不懂，隐私！'
            });
        }
    });
});

